const axios = require('axios');
const MockAdapter = require('axios-mock-adapter');
const normalAxios = axios.create();
const mockAxios = axios.create();
import Config from "./config";
import {jsonToTreeJson} from "../utils";
import reqTools from "../utils/reqTools";

// 区域管理
var mock = new MockAdapter(mockAxios);

mock.onGet('/getAreaByParent').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get( '/api/sysArea/findByParent?parentId='+config.id ).then((res) => {
      resolve([200, res ]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

mock.onGet('/getAreaById').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get( '/api/sysArea/'+config.id).then((res) => {
      resolve([200, res ]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

mock.onPost('/addArea').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.post( '/api/sysArea',config.data
    ).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
mock.onDelete('/delArea').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.delete('/api/sysArea/'+config.id).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
mock.onPut('/updateArea').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.put( '/api/sysArea', config.data, 
   ).then((res) => {
      resolve([200, res ]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});





export default mockAxios;
